package com.epam.javalab.giorgadze.task2.logic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;

public class Reader {
    private static final Logger log = LoggerFactory.getLogger(Parser.class);

    public static String readTextFromFile(String fileName) throws IOException {
        return new Scanner(Reader.class.getClassLoader().getResourceAsStream(fileName)).useDelimiter("\\A").next();
    }

    public static String readFromProperties(String propertyName, String parserName) {
        Properties prop = new Properties();
        String regex = null;
        try {
            prop.load(new FileInputStream(propertyName));
            regex = prop.getProperty(parserName);
            log.info("Regex extracted from property file");
        } catch (IOException e) {
            log.error("Could not read regex from file!");
        }
        return regex;
    }

}
